package im.dhc.gitdiff.util;

import java.io.InputStream;
import java.util.HashMap;
import java.util.Map;
import java.util.Properties;
import java.util.Map.Entry;

public class PropertityUtil {

	private String configPath = "/conf.properties";
	private Properties props = new Properties();
	
	public PropertityUtil() throws Exception {
		//InputStream in = new FileInputStream(new File(PropertityUtil.class.getResource("/"+configPath).getFile()));
		InputStream in = PropertityUtil.class.getResourceAsStream(configPath);
		
		props.load(in);
		in.close();
	}
	
	public String getProperty(String key) {
		return props.getProperty(key);
	}
	
	public Map<String,String> readAllProperties() {
		Map<String,String> map = new HashMap<String,String>();
		
		for (Entry<Object, Object> entry : props.entrySet()) {
            String stringKey = String.valueOf(entry.getKey());
            String stringValue = String.valueOf(entry.getValue());
            map.put(stringKey, stringValue);
        }
				
		return map;
	}
	
	public static void main(String[] args) throws Exception {
		PropertityUtil util = new PropertityUtil();
		
		String value = util.getProperty("name");
		System.out.print(value);
	}
}
